<template>
	<view class="detail">
		<view class="nav nav_bar flex_r_between" :style="`background: rgba(255, 255, 255,${trans});padding-left: 32rpx;padding-right: 32rpx;`">
			<view style="width: 30px;height: 30px;background-color: rgba(0, 0, 0,0.6);border-radius: 15px;"
				class="flex_r_around" @click="back">
				<uni-icons type="back" size="20" color="#FFF"></uni-icons>
			</view>

			<view class="actions flex_center">
				<view @click="toEdit">编辑</view>
				<view @click="onDetele">删除</view>
			</view>
		</view>

		<view class="header_banner">
			<swiper class="swiper-box" @change="change" :current="current">
				<swiper-item v-for="(item, index) in data.goods_image" :key="index">
					<image @click="$util.previewImage(data.goods_image , index)" :src="item" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
			<view class="current" v-if="data.goods_image">
				{{current+1}}/{{data.goods_image.length}}
			</view>
		</view>


		<view class="banner_preview">
			<scroll-view scroll-x="true">
				<view class="banner_list flex_center">
					<image :src="item" mode="aspectFill" v-for="(item,index) in data.goods_image" :key="index"
						:id="index == current ? 'select' : ''" @click="current = index"></image>
				</view>
			</scroll-view>
		</view>

		<view class="goods_name_view">
			<view class="goods_name">{{data.name}}</view>
			<view class="price flex_r_between">
				<view class="price_text"><i>￥</i>{{data.price}}</view>
				<view class="order_num">售出 {{data.order_num}}</view>
			</view>
			<view class="tags">
				商品类型・{{data.p_category_name}}・{{data.category_name}}
			</view>
			
			<view class="tags">
				快递方式：{{ data.express_type == 1 ? '到店使用' : data.express_type == 2 ? '送货上门' : '快递邮寄' }}
			</view>
			
		</view>

		<view class="liner"></view>

		<view class="content">
			<view class="content_title">商品详情</view>
			<view class="content_text">
				<rich-text :nodes="data.content"></rich-text>
			</view>
			<image @click="$util.previewImage(data.content_images , index)" :src="item" mode="widthFix" v-for="(item,index) in data.content_images" :key="index"></image>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				goods_id: 0,

				// 轮播图指示点
				current: 0,

				data: {},

				trans: 0,
			}
		},
		methods: {
			back() {
				uni.navigateBack()
			},

			getDetail() {
				this.$get(`/store_goods/getGoodsInfo?goods_id`, {
					'goods_id': this.goods_id
				}).then(res => {
					this.data = res.data;
				});
			},

			change(e) {
				this.current = e.detail.current;
			},

			toEdit() {
				uni.navigateTo({
					url: `/pages/store/product/productAdd?data=${JSON.stringify(this.data)}`
				})
			},

			onDetele() {
				this.$post('/store_goods/delGoods', {
					goods_id: this.data.id,
				}).then(res => {
					this.$util.msg(res.msg);
					this.$util.back()
				})
			},
		},

		onLoad(option) {
			this.goods_id = option.id;
		},
		
		onShow(){
			this.getDetail()
		},

		onPageScroll: function(e) { //nvue暂不支持滚动监听，可用bindingx代替
			if (e.scrollTop <= 200) {
				this.trans = e.scrollTop / 200;
			} else {
				this.trans = 1
			}
		},
	}
</script>

<style lang="less" scoped>
	.detail {
		background: #FFF;
		min-height: 100vh;
	}

	.actions {
		view {
			height: 48rpx;
			background: #FD2A53;
			border-radius: 24rpx;
			padding: 0 20rpx;
			font-weight: 500;
			font-size: 28rpx;
			line-height: 48rpx;
			color: #FFF;
			margin-left: 16rpx;
		}
	}

	.header_banner {
		width: 100vw;
		height: 100vw;

		position: relative;

		.swiper-box {
			width: 100vw;
			height: 100vw;

			swiper-item {
				width: 100vw;
				height: 100vw;

				image {
					width: 100vw;
					height: 100vw;
				}
			}
		}

		.current {
			position: absolute;
			right: 32rpx;
			bottom: 30rpx;
			height: 38rpx;
			background: rgba(0, 0, 0, 0.5);
			border-radius: 20rpx;
			padding: 0 12rpx;
			font-weight: 500;
			font-size: 24rpx;
			color: #FFFFFF;
			line-height: 38rpx;
		}
	}

	.banner_preview {
		margin: 32rpx;

		.banner_list {
			image {
				flex-shrink: 0;
				width: 96rpx;
				height: 96rpx;
				border-radius: 16rpx;
				margin-right: 16rpx;
				border: 4rpx solid transparent;
			}
		}

		#select {
			border: 4rpx solid #FD2A53;
		}
	}

	.goods_name_view {
		padding: 0 32rpx;

		.goods_name {
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			color: #131313;
			line-height: 44rpx;
			text-align: left;
			font-style: normal;
		}

		.price {
			padding: 32rpx 0;
			border-bottom: 1rpx solid #EEEEEE;

			.price_text {
				i {
					font-size: 36rpx;
					font-style: normal;
				}

				font-weight: 600;
				font-size: 48rpx;
				color: #FD2A53;
				line-height: 48rpx;
			}

			.order_num {
				font-size: 24rpx;
				color: #999999;
			}


		}

		.tags {
			margin-top: 24rpx;
			font-size: 28rpx;
			color: #666666;
		}
	}

	.liner {
		width: 100vw;
		height: 16rpx;
		background: #F1F1F1;
		margin: 40rpx 0 32rpx;
	}

	.content {
		.content_title {
			padding: 0 32rpx;
			font-weight: 500;
			font-size: 32rpx;
			color: #131313;
		}

		.content_text {
			padding: 0 32rpx;
			font-size: 28rpx;
			color: #666666;
			margin: 20rpx 0 32rpx;
		}

		image {
			width: 100vw;
		}
	}
</style>